﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CarFrameWork.Common;
namespace CarFrameWork.Model.CanShuHua
{
	/// <summary>
	/// 类内挡油板。
	/// </summary>
	[Serializable]
	public partial class 内挡油板
	{
		public 内挡油板()
		{}
		#region Model
		private int _id;
		private string _name;
		private string _path;
		private float _r2;
		private float _r3;
		private float _r4;
		private float _h2;
		private float _d;
		/// <summary>
		/// 
		/// </summary>
		public int ID
		{
			set{ _id=value;}
			get{return _id;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string name
		{
			set{ _name=value;}
			get{return _name;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string path
		{
			set{ _path=value;}
			get{return _path;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float R2
		{
			set{ _r2=value;}
			get{return _r2;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float R3
		{
			set{ _r3=value;}
			get{return _r3;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float R4
		{
			set{ _r4=value;}
			get{return _r4;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float H2
		{
			set{ _h2=value;}
			get{return _h2;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D
		{
			set{ _d=value;}
			get{return _d;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public 内挡油板(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,name,path,R2,R3,R4,H2,D ");
			strSql.Append(" FROM [内挡油板] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					this.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["path"]!=null && ds.Tables[0].Rows[0]["path"].ToString()!="")
				{
					this.path=ds.Tables[0].Rows[0]["path"].ToString();
				}
				if(ds.Tables[0].Rows[0]["R2"]!=null && ds.Tables[0].Rows[0]["R2"].ToString()!="")
				{
					this.R2=float.Parse(ds.Tables[0].Rows[0]["R2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["R3"]!=null && ds.Tables[0].Rows[0]["R3"].ToString()!="")
				{
					this.R3=float.Parse(ds.Tables[0].Rows[0]["R3"].ToString());
				}
				if(ds.Tables[0].Rows[0]["R4"]!=null && ds.Tables[0].Rows[0]["R4"].ToString()!="")
				{
					this.R4=float.Parse(ds.Tables[0].Rows[0]["R4"].ToString());
				}
				if(ds.Tables[0].Rows[0]["H2"]!=null && ds.Tables[0].Rows[0]["H2"].ToString()!="")
				{
					this.H2=float.Parse(ds.Tables[0].Rows[0]["H2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D"]!=null && ds.Tables[0].Rows[0]["D"].ToString()!="")
				{
					this.D=float.Parse(ds.Tables[0].Rows[0]["D"].ToString());
				}
			}
		}

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{

		return DbHelperSQL.GetMaxID("ID", "内挡油板"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from [内挡油板]");
			strSql.Append(" where ID=@ID ");

			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [内挡油板] (");
			strSql.Append("name,path,R2,R3,R4,H2,D)");
			strSql.Append(" values (");
			strSql.Append("@name,@path,@R2,@R3,@R4,@H2,@D)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.NVarChar,50),
					new SqlParameter("@path", SqlDbType.NVarChar),
					new SqlParameter("@R2", SqlDbType.Float,8),
					new SqlParameter("@R3", SqlDbType.Float,8),
					new SqlParameter("@R4", SqlDbType.Float,8),
					new SqlParameter("@H2", SqlDbType.Float,8),
					new SqlParameter("@D", SqlDbType.Float,8)};
			parameters[0].Value = name;
			parameters[1].Value = path;
			parameters[2].Value = R2;
			parameters[3].Value = R3;
			parameters[4].Value = R4;
			parameters[5].Value = H2;
			parameters[6].Value = D;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update [内挡油板] set ");
			strSql.Append("name=@name,");
			strSql.Append("path=@path,");
			strSql.Append("R2=@R2,");
			strSql.Append("R3=@R3,");
			strSql.Append("R4=@R4,");
			strSql.Append("H2=@H2,");
			strSql.Append("D=@D");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.NVarChar,50),
					new SqlParameter("@path", SqlDbType.NVarChar),
					new SqlParameter("@R2", SqlDbType.Float,8),
					new SqlParameter("@R3", SqlDbType.Float,8),
					new SqlParameter("@R4", SqlDbType.Float,8),
					new SqlParameter("@H2", SqlDbType.Float,8),
					new SqlParameter("@D", SqlDbType.Float,8),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = name;
			parameters[1].Value = path;
			parameters[2].Value = R2;
			parameters[3].Value = R3;
			parameters[4].Value = R4;
			parameters[5].Value = H2;
			parameters[6].Value = D;
			parameters[7].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from [内挡油板] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,name,path,R2,R3,R4,H2,D ");
			strSql.Append(" FROM [内挡油板] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					this.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["path"]!=null && ds.Tables[0].Rows[0]["path"].ToString()!="")
				{
					this.path=ds.Tables[0].Rows[0]["path"].ToString();
				}
				if(ds.Tables[0].Rows[0]["R2"]!=null && ds.Tables[0].Rows[0]["R2"].ToString()!="")
				{
					this.R2=float.Parse(ds.Tables[0].Rows[0]["R2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["R3"]!=null && ds.Tables[0].Rows[0]["R3"].ToString()!="")
				{
					this.R3=float.Parse(ds.Tables[0].Rows[0]["R3"].ToString());
				}
				if(ds.Tables[0].Rows[0]["R4"]!=null && ds.Tables[0].Rows[0]["R4"].ToString()!="")
				{
					this.R4=float.Parse(ds.Tables[0].Rows[0]["R4"].ToString());
				}
				if(ds.Tables[0].Rows[0]["H2"]!=null && ds.Tables[0].Rows[0]["H2"].ToString()!="")
				{
					this.H2=float.Parse(ds.Tables[0].Rows[0]["H2"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D"]!=null && ds.Tables[0].Rows[0]["D"].ToString()!="")
				{
					this.D=float.Parse(ds.Tables[0].Rows[0]["D"].ToString());
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM [内挡油板] ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

